package com.aprivate.kn.ratingsystem.daoutil;

import android.util.Log;

import com.aprivate.kn.ratingsystem.RatingApplication;
import com.aprivate.kn.ratingsystem.dao.DaoManager;
import com.aprivate.kn.ratingsystem.dao.IntervieweeDao;
import com.aprivate.kn.ratingsystem.daoBean.Interviewee;
import com.aprivate.kn.ratingsystem.daoBean.User;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

public class IntervieweeDaoUtil {
    private DaoManager mManager;
    private String TAG = "flag";

    static final class Holder {
        private static final IntervieweeDaoUtil instance = new IntervieweeDaoUtil();
    }

    public static IntervieweeDaoUtil getInstance() {
        return IntervieweeDaoUtil.Holder.instance;
    }

    //操作Fruit的构造函数
    public IntervieweeDaoUtil() {
        mManager = DaoManager.getInstance();
        mManager.init(RatingApplication.sApp);
    }

    /**
     * 完成user记录的插入，如果表未创建，先创建user表
     *
     * @param user
     * @return 返回long值 -1为失败
     */
    public boolean insertUser(Interviewee user) {
        boolean flag = false;
        flag = mManager.getDaoSession().getIntervieweeDao().insertOrReplace(user) == -1 ? false : true;
        Log.i(TAG, "-------插入一条的结果为" + flag);
        return flag;
    }

    public List<Interviewee> queryIntervieweeByProjectId(String projectId) {
        QueryBuilder<Interviewee> queryBuilder = mManager.getDaoSession().queryBuilder(Interviewee.class);
        return queryBuilder.where(IntervieweeDao.Properties.ProductInfoId.eq(projectId)).list();
    }
}
